package com.LeeCode;

/**
 * 找出数组中的幸运数
 */

public class Code1394 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 2, 3, 3, 3};
        System.out.println(new Code1394().findLucky(arr));
    }

    public int findLucky(int[] arr) {
        int[] cnt = new int[arr.length + 1];
        for (int num : arr) {
            if (num <= arr.length) {
                cnt[num]++;
            }
        }

        for (int i = cnt.length - 1; i >= 1; i--) {
            if (cnt[i] == i) return i;
        }
        return -1;
    }
}
